package id.co.rho.scoring.cid.shared.model;

import java.util.List;

import id.co.rho.scoring.cid.changecontrol.entitychange.UpdateEntityChange;
import id.co.rho.scoring.cid.client.model.ChangeTrackingModel;

public class AppFunctionModel extends ChangeTrackingModel{
	private static final long serialVersionUID = 1L;
	public static final String ID = "id";
	public static final String FUNCTION_CODE = "functionCode";
	public static final String FUNCTION_NAME = "functionName";
	public static final String FUNCTION_STATUS = "functionStatus";
	public static final String FUNCTION_DESC = "functionDesc";
	public static final String FUNCTION_LVL = "functionLevel";
	
	public AppFunctionModel() {
		super();
	}
	
	public AppFunctionModel(UpdateEntityChange change) {
		super(change);
	}
	
	public static List<AppFunctionModel> applyChanges(List<AppFunctionModel> modelList, List<UpdateEntityChange> uecList){
    	Long idModel, idUec;
    	AppFunctionModel newModel;
    	if(uecList!=null){
	    	for (UpdateEntityChange change : uecList) {
				idUec = (Long) change.getEntityId();
				if(idUec!=null){
			    	for (AppFunctionModel model : modelList) {
			    		idModel = (Long) model.get(LitigationModel.ID);    		
		    			if(idModel.compareTo(idUec)==0){
		    				model.setChange(change);
		    			}
		    		}
				}else{
					newModel = new AppFunctionModel(change);
					modelList.add(newModel);
				}
	    	}
    	}
    	return modelList;
    }
}
